﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CSmcCs;

namespace Setting
{
	/// <summary>
	/// Summary description for Setting.
	/// </summary>
	public class Setting : System.Windows.Forms.Form
	{
		internal System.Windows.Forms.GroupBox GroupBox2;
		internal System.Windows.Forms.Label Label4;
		internal System.Windows.Forms.GroupBox GroupBox1;
		internal System.Windows.Forms.Label Label3;
		internal System.Windows.Forms.Label Label2;
		internal System.Windows.Forms.Label DeviceName;
		internal System.Windows.Forms.TextBox txtDevice;
		internal System.Windows.Forms.Button btnExit;
		internal System.Windows.Forms.Button btnComOrgSet;
		internal System.Windows.Forms.Button btnComStatus;
		internal System.Windows.Forms.Button btnComSet;
		internal System.Windows.Forms.Button btnComLtcClrSet;
		internal System.Windows.Forms.Button btnComErcAlmClrSet;
		internal System.Windows.Forms.Button btnComLogicSet;
		internal System.Windows.Forms.Button btnComInOutSet;
		internal System.Windows.Forms.ComboBox cboEncType;
		internal System.Windows.Forms.ComboBox cboPlsType;
		internal System.Windows.Forms.CheckBox chkSAcc;
		internal System.Windows.Forms.CheckBox chkDirTimer;
		internal System.Windows.Forms.ComboBox cboTargetAxis;
		private System.Windows.Forms.TextBox txtErrorString;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		InOutSet			InOutSetDlg = new InOutSet();
		LogicSet			LogicSetDlg = new LogicSet();
		OrgSet				OrgSetDlg = new OrgSet();
		ErcAlmClrSet		ErcAlmClrSetDlg = new ErcAlmClrSet();
		LtcClrSet			LtcClrSetDlg = new LtcClrSet();

		/////////////////////////////////////////////////
		// SMC access function
		/////////////////////////////////////////////////
		public static short	DevId=-1;
		public static int	Ret;
		public static short	AxisNo;
		public static short	PulseType, DirTimer;
		public static short	EncType;
		public static short	CtrlOut1, CtrlOut2, CtrlOut3;
		public static short	CtrlIn;
		public static short	OrgLog;
		public static short	CtrlInOutLog;
		public static short	ErcMode;
		public static short	ErcTime, ErcOffTimer, AlmTime;
		public static short	LimitTurn, OrgType, EndDir, ZCount;
		public static short	SAccelType;
		public static short	FilterType;
		public static short	SDMode;
		public static short	ClearCntLtc, LtcMode, ClearCntClr, ClrMode;
		public static short	InitParam;

		string				Text_ErrorString;

		CSmc				Smc	= new CSmc();

		public Setting()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.btnExit = new System.Windows.Forms.Button();
			this.btnComOrgSet = new System.Windows.Forms.Button();
			this.btnComStatus = new System.Windows.Forms.Button();
			this.btnComSet = new System.Windows.Forms.Button();
			this.btnComLtcClrSet = new System.Windows.Forms.Button();
			this.btnComErcAlmClrSet = new System.Windows.Forms.Button();
			this.btnComLogicSet = new System.Windows.Forms.Button();
			this.btnComInOutSet = new System.Windows.Forms.Button();
			this.GroupBox2 = new System.Windows.Forms.GroupBox();
			this.cboEncType = new System.Windows.Forms.ComboBox();
			this.Label4 = new System.Windows.Forms.Label();
			this.GroupBox1 = new System.Windows.Forms.GroupBox();
			this.cboPlsType = new System.Windows.Forms.ComboBox();
			this.chkSAcc = new System.Windows.Forms.CheckBox();
			this.chkDirTimer = new System.Windows.Forms.CheckBox();
			this.Label3 = new System.Windows.Forms.Label();
			this.cboTargetAxis = new System.Windows.Forms.ComboBox();
			this.txtDevice = new System.Windows.Forms.TextBox();
			this.Label2 = new System.Windows.Forms.Label();
			this.DeviceName = new System.Windows.Forms.Label();
			this.txtErrorString = new System.Windows.Forms.TextBox();
			this.GroupBox2.SuspendLayout();
			this.GroupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// btnExit
			// 
			this.btnExit.Location = new System.Drawing.Point(326, 328);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(88, 38);
			this.btnExit.TabIndex = 12;
			this.btnExit.Text = "Exit";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// btnComOrgSet
			// 
			this.btnComOrgSet.Location = new System.Drawing.Point(256, 244);
			this.btnComOrgSet.Name = "btnComOrgSet";
			this.btnComOrgSet.Size = new System.Drawing.Size(104, 32);
			this.btnComOrgSet.TabIndex = 6;
			this.btnComOrgSet.Text = "ORG Setting";
			this.btnComOrgSet.Click += new System.EventHandler(this.btnComOrgSet_Click);
			// 
			// btnComStatus
			// 
			this.btnComStatus.Location = new System.Drawing.Point(114, 328);
			this.btnComStatus.Name = "btnComStatus";
			this.btnComStatus.Size = new System.Drawing.Size(88, 38);
			this.btnComStatus.TabIndex = 10;
			this.btnComStatus.Text = "Status";
			this.btnComStatus.Click += new System.EventHandler(this.btnComStatus_Click);
			// 
			// btnComSet
			// 
			this.btnComSet.Location = new System.Drawing.Point(8, 328);
			this.btnComSet.Name = "btnComSet";
			this.btnComSet.Size = new System.Drawing.Size(88, 38);
			this.btnComSet.TabIndex = 9;
			this.btnComSet.Text = "Set";
			this.btnComSet.Click += new System.EventHandler(this.btnComSet_Click);
			// 
			// btnComLtcClrSet
			// 
			this.btnComLtcClrSet.Location = new System.Drawing.Point(200, 286);
			this.btnComLtcClrSet.Name = "btnComLtcClrSet";
			this.btnComLtcClrSet.Size = new System.Drawing.Size(160, 32);
			this.btnComLtcClrSet.TabIndex = 8;
			this.btnComLtcClrSet.Text = "LTC/CLR Setting";
			this.btnComLtcClrSet.Click += new System.EventHandler(this.btnComLtcClrSet_Click);
			// 
			// btnComErcAlmClrSet
			// 
			this.btnComErcAlmClrSet.Location = new System.Drawing.Point(8, 286);
			this.btnComErcAlmClrSet.Name = "btnComErcAlmClrSet";
			this.btnComErcAlmClrSet.Size = new System.Drawing.Size(160, 32);
			this.btnComErcAlmClrSet.TabIndex = 7;
			this.btnComErcAlmClrSet.Text = "ERC/ALM Clear Setting";
			this.btnComErcAlmClrSet.Click += new System.EventHandler(this.btnComErcAlmClrSet_Click);
			// 
			// btnComLogicSet
			// 
			this.btnComLogicSet.Location = new System.Drawing.Point(132, 244);
			this.btnComLogicSet.Name = "btnComLogicSet";
			this.btnComLogicSet.Size = new System.Drawing.Size(104, 32);
			this.btnComLogicSet.TabIndex = 5;
			this.btnComLogicSet.Text = "Logic Setting";
			this.btnComLogicSet.Click += new System.EventHandler(this.btnComLogicSet_Click);
			// 
			// btnComInOutSet
			// 
			this.btnComInOutSet.Location = new System.Drawing.Point(8, 244);
			this.btnComInOutSet.Name = "btnComInOutSet";
			this.btnComInOutSet.Size = new System.Drawing.Size(104, 32);
			this.btnComInOutSet.TabIndex = 4;
			this.btnComInOutSet.Text = "In/Out Setting";
			this.btnComInOutSet.Click += new System.EventHandler(this.btnComInOutSet_Click);
			// 
			// GroupBox2
			// 
			this.GroupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.cboEncType,
																					this.Label4});
			this.GroupBox2.Location = new System.Drawing.Point(8, 168);
			this.GroupBox2.Name = "GroupBox2";
			this.GroupBox2.Size = new System.Drawing.Size(408, 64);
			this.GroupBox2.TabIndex = 3;
			this.GroupBox2.TabStop = false;
			this.GroupBox2.Text = "PulseIn";
			// 
			// cboEncType
			// 
			this.cboEncType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboEncType.Location = new System.Drawing.Point(104, 22);
			this.cboEncType.Name = "cboEncType";
			this.cboEncType.Size = new System.Drawing.Size(296, 23);
			this.cboEncType.TabIndex = 1;
			this.cboEncType.SelectedIndexChanged += new System.EventHandler(this.cboEncType_SelectedIndexChanged);
			// 
			// Label4
			// 
			this.Label4.AutoSize = true;
			this.Label4.Location = new System.Drawing.Point(9, 24);
			this.Label4.Name = "Label4";
			this.Label4.Size = new System.Drawing.Size(81, 14);
			this.Label4.TabIndex = 0;
			this.Label4.Text = "EncoderType:";
			// 
			// GroupBox1
			// 
			this.GroupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.cboPlsType,
																					this.chkSAcc,
																					this.chkDirTimer,
																					this.Label3});
			this.GroupBox1.Location = new System.Drawing.Point(8, 40);
			this.GroupBox1.Name = "GroupBox1";
			this.GroupBox1.Size = new System.Drawing.Size(408, 120);
			this.GroupBox1.TabIndex = 2;
			this.GroupBox1.TabStop = false;
			this.GroupBox1.Text = "PulseOut";
			// 
			// cboPlsType
			// 
			this.cboPlsType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboPlsType.Location = new System.Drawing.Point(88, 24);
			this.cboPlsType.Name = "cboPlsType";
			this.cboPlsType.Size = new System.Drawing.Size(312, 23);
			this.cboPlsType.TabIndex = 1;
			this.cboPlsType.SelectedIndexChanged += new System.EventHandler(this.cboPlsType_SelectedIndexChanged);
			// 
			// chkSAcc
			// 
			this.chkSAcc.Location = new System.Drawing.Point(9, 88);
			this.chkSAcc.Name = "chkSAcc";
			this.chkSAcc.Size = new System.Drawing.Size(200, 24);
			this.chkSAcc.TabIndex = 3;
			this.chkSAcc.Text = "S Accel/Decel Use";
			this.chkSAcc.CheckedChanged += new System.EventHandler(this.chkSAcc_CheckedChanged);
			// 
			// chkDirTimer
			// 
			this.chkDirTimer.Location = new System.Drawing.Point(9, 56);
			this.chkDirTimer.Name = "chkDirTimer";
			this.chkDirTimer.Size = new System.Drawing.Size(200, 24);
			this.chkDirTimer.TabIndex = 2;
			this.chkDirTimer.Text = "Reverse Direction Timer ON";
			this.chkDirTimer.CheckedChanged += new System.EventHandler(this.chkDirTimer_CheckedChanged);
			// 
			// Label3
			// 
			this.Label3.AutoSize = true;
			this.Label3.Location = new System.Drawing.Point(9, 26);
			this.Label3.Name = "Label3";
			this.Label3.Size = new System.Drawing.Size(70, 14);
			this.Label3.TabIndex = 0;
			this.Label3.Text = "Pulse Type:";
			// 
			// cboTargetAxis
			// 
			this.cboTargetAxis.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboTargetAxis.Location = new System.Drawing.Point(304, 9);
			this.cboTargetAxis.Name = "cboTargetAxis";
			this.cboTargetAxis.Size = new System.Drawing.Size(80, 23);
			this.cboTargetAxis.TabIndex = 1;
			this.cboTargetAxis.SelectedIndexChanged += new System.EventHandler(this.cboTargetAxis_SelectedIndexChanged);
			// 
			// txtDevice
			// 
			this.txtDevice.Location = new System.Drawing.Point(96, 10);
			this.txtDevice.Name = "txtDevice";
			this.txtDevice.Size = new System.Drawing.Size(104, 21);
			this.txtDevice.TabIndex = 0;
			this.txtDevice.Text = "";
			this.txtDevice.TextChanged += new System.EventHandler(this.txtDevice_TextChanged);
			// 
			// Label2
			// 
			this.Label2.AutoSize = true;
			this.Label2.Location = new System.Drawing.Point(240, 13);
			this.Label2.Name = "Label2";
			this.Label2.Size = new System.Drawing.Size(47, 14);
			this.Label2.TabIndex = 17;
			this.Label2.Text = "AxisNo:";
			// 
			// DeviceName
			// 
			this.DeviceName.AutoSize = true;
			this.DeviceName.Location = new System.Drawing.Point(8, 13);
			this.DeviceName.Name = "DeviceName";
			this.DeviceName.Size = new System.Drawing.Size(82, 14);
			this.DeviceName.TabIndex = 16;
			this.DeviceName.Text = "Device Name:";
			// 
			// txtErrorString
			// 
			this.txtErrorString.AutoSize = false;
			this.txtErrorString.Location = new System.Drawing.Point(8, 384);
			this.txtErrorString.Name = "txtErrorString";
			this.txtErrorString.Size = new System.Drawing.Size(408, 64);
			this.txtErrorString.TabIndex = 13;
			this.txtErrorString.Text = "";
			// 
			// Setting
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(424, 454);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.txtErrorString,
																		  this.btnExit,
																		  this.btnComOrgSet,
																		  this.btnComStatus,
																		  this.btnComSet,
																		  this.btnComLtcClrSet,
																		  this.btnComErcAlmClrSet,
																		  this.btnComLogicSet,
																		  this.btnComInOutSet,
																		  this.GroupBox2,
																		  this.GroupBox1,
																		  this.cboTargetAxis,
																		  this.txtDevice,
																		  this.Label2,
																		  this.DeviceName});
			this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "Setting";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Setting";
			this.Load += new System.EventHandler(this.Setting_Load);
			this.GroupBox2.ResumeLayout(false);
			this.GroupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Setting());
		}

		private void Setting_Load(object sender, System.EventArgs e)
		{
			// CComboBox
			// PulseType ComboBox
			cboPlsType.Items.Add("PULSE/DIR,OUT:Low,DIR+:High,DIR-:Low");
			cboPlsType.Items.Add("PULSE/DIR,OUT:High,DIR+:High,DIR-:Low");
			cboPlsType.Items.Add("PULSE/DIR,OUT:Low,DIR+:Low,DIR-:High");
			cboPlsType.Items.Add("PULSE/DIR,OUT:High,DIR+:Low,DIR-:High");
			cboPlsType.Items.Add("CW/CCW:Low");
			cboPlsType.Items.Add("CW/CCW:High");
			cboPlsType.Items.Add("DIFFERENCE:OUT:Leading,DIR:Trailing");
			cboPlsType.Items.Add("DIFFERENCE:OUT:Trailing,DIR:Leading");
			cboPlsType.SelectedIndex = 0;

			// EncoderType ComboBox
			cboEncType.Items.Add("A/B two-phase input 1 times");
			cboEncType.Items.Add("A/B two-phase input 2 times");
			cboEncType.Items.Add("A/B two-phase input 4 times");
			cboEncType.Items.Add("U/D single-phase input 1 times");
			cboEncType.Items.Add("Not use");
			cboEncType.SelectedIndex = 0;

			// AxisNo ComboBox
			for( int i = 0; i < 8; i++ )
			{
				string	str;
				str =string.Format("{0:d}", i+1);
				cboTargetAxis.Items.Add(str);
			}
			// CEdit
			txtDevice.Text = ("SMC000");

			AxisNo=1;
			// ComboBox Initialise
			cboTargetAxis.SelectedIndex = AxisNo - 1;
			
			FormUpdate();
		}

		/////////////////////////////////////////////////////////////////
		// SMC function
		/////////////////////////////////////////////////////////////////
		private bool GetInitParam()
		{
			Ret = Smc.WGetPulseType(DevId, AxisNo, out PulseType, out DirTimer);
			Ret = Smc.WGetEncType(DevId, AxisNo, out EncType);
			Ret = Smc.WGetCtrlTypeOut(DevId, AxisNo, out CtrlOut1, out CtrlOut2, out CtrlOut3);
			Ret = Smc.WGetCtrlTypeIn(DevId, AxisNo, out CtrlIn);
			Ret = Smc.WGetOrgLog(DevId, AxisNo, out OrgLog);
			Ret = Smc.WGetCtrlInOutLog(DevId, AxisNo, out CtrlInOutLog);
			Ret = Smc.WGetErcMode(DevId, AxisNo, out ErcMode);
			Ret = Smc.WGetErcAlmClearTime(DevId, AxisNo, out ErcTime, out ErcOffTimer, out AlmTime);
			Ret = Smc.WGetOrgMode(DevId, AxisNo, out LimitTurn, out OrgType, out EndDir, out ZCount);
			Ret = Smc.WGetSAccelType(DevId, AxisNo, out SAccelType);
			Ret = Smc.WGetInFilterType(DevId, AxisNo, out FilterType);
			Ret = Smc.WGetSDMode(DevId, AxisNo, out SDMode);
			Ret = Smc.WGetCounterMode(DevId, AxisNo, out ClearCntLtc, out LtcMode, out ClearCntClr, out ClrMode);
			Ret = Smc.WGetInitParam(DevId, AxisNo, out InitParam);
			return true;
		}

		// "Reverse Direction Timer ON" Clicked
		private void chkDirTimer_CheckedChanged(object sender, System.EventArgs e)
		{
			if ( chkDirTimer.Checked == true )
			{
				DirTimer = 1;
			}
			else if ( chkDirTimer.Checked == false )
			{
				DirTimer = 0;
			}
		}

		// "S Accel/Decel Use" Clicked
		private void chkSAcc_CheckedChanged(object sender, System.EventArgs e)
		{
			if ( chkSAcc.Checked == true )
			{
				SAccelType = 1;
			}
			else if ( chkSAcc.Checked == false )
			{
				SAccelType = 0;
			}
		}

		// "PulseOut(Pulse Type:)" Select Change
		private void cboPlsType_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			PulseType=(short)cboPlsType.SelectedIndex;
		}

		// "PulseIn(EncoderType:)" Select Change
		private void cboEncType_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			EncType=(short)cboEncType.SelectedIndex;
		}

		// Parameta read & Display Form set
		private void FormUpdate()
		{
			bool	bRet;
			bRet=GetInitParam();

			// ComboBox Initialise
			cboPlsType.SelectedIndex = PulseType;
			cboEncType.SelectedIndex = EncType;

			// Reverse Direction Timer ON
			if ( DirTimer == 1 )
			{
				chkDirTimer.Checked = true;
			}
			else if ( DirTimer == 0 )
			{
				chkDirTimer.Checked = false;
			}

			// S Accel/Decel Use
			if ( SAccelType  == 1 )
			{
				chkSAcc.Checked = true;
			}
			else if ( SAccelType  == 0 )
			{
				chkSAcc.Checked = false;
			}
		}

		// "In/Out Setting" Button clicked
		private void btnComInOutSet_Click(object sender, System.EventArgs e)
		{
			InOutSetDlg.ShowDialog();
		}

		// "Logic Setting" Button clicked
		private void btnComLogicSet_Click(object sender, System.EventArgs e)
		{
			LogicSetDlg.ShowDialog();
		}

		// "ORG Setting" Button clicked
		private void btnComOrgSet_Click(object sender, System.EventArgs e)
		{
			OrgSetDlg.ShowDialog();
		}

		// "ERC/ALM Clear Setting" Button clicked
		private void btnComErcAlmClrSet_Click(object sender, System.EventArgs e)
		{
			ErcAlmClrSetDlg.ShowDialog();
		}

		// "LTC/CLR Setting" Button clicked
		private void btnComLtcClrSet_Click(object sender, System.EventArgs e)
		{
			LtcClrSetDlg.ShowDialog();
		}

		// "Set" Button clicked
		private void btnComSet_Click(object sender, System.EventArgs e)
		{
			Ret = Smc.WSetPulseType(DevId, AxisNo, PulseType, DirTimer);
			Ret = Smc.WSetEncType(DevId, AxisNo, EncType);
			Ret = Smc.WSetCtrlTypeOut(DevId, AxisNo, CtrlOut1, CtrlOut2, CtrlOut3);
			Ret = Smc.WSetCtrlTypeIn(DevId, AxisNo, CtrlIn);
			Ret = Smc.WSetOrgLog(DevId, AxisNo, OrgLog);
			Ret = Smc.WSetCtrlInOutLog(DevId, AxisNo, CtrlInOutLog);
			Ret = Smc.WSetErcMode(DevId, AxisNo, ErcMode);
			Ret = Smc.WSetErcAlmClearTime(DevId, AxisNo, ErcTime, ErcOffTimer, AlmTime);
			Ret = Smc.WSetOrgMode(DevId, AxisNo, LimitTurn, OrgType, EndDir, ZCount);
			Ret = Smc.WSetErcMode(DevId, AxisNo, ErcMode);
			Ret = Smc.WSetSAccelType(DevId, AxisNo, SAccelType);
			Ret = Smc.WSetInFilterType(DevId, AxisNo, FilterType);
			Ret = Smc.WSetSDMode(DevId, AxisNo, SDMode);
			Ret = Smc.WSetCounterMode(DevId, AxisNo, ClearCntLtc, LtcMode, ClearCntClr, ClrMode);
			Ret = Smc.WSetInitParam(DevId, AxisNo);
    
			Text_ErrorString = string.Format("SmcSetInitParam = {0:d}", Ret );
			txtErrorString.Text = Text_ErrorString;
		}

		// "Status" Button clicked
		private void btnComStatus_Click(object sender, System.EventArgs e)
		{
			short	InitParam;
			Ret = Smc.WGetInitParam(DevId, AxisNo, out InitParam);

			Text_ErrorString = string.Format("SmcGetInitParam = {0:d}", Ret );

			if( InitParam == 1 )
			{
				Text_ErrorString +=": Initial Setting [ OK ]";
			}
			else
			{
				Text_ErrorString +=": Initial Setting [ None ]";
			}
			txtErrorString.Text = Text_ErrorString;
		}

		// "exit" Button clicked
		private void btnExit_Click(object sender, System.EventArgs e)
		{
			InOutSetDlg.Dispose();
			LogicSetDlg.Dispose();
			OrgSetDlg.Dispose();
			ErcAlmClrSetDlg.Dispose();
			LtcClrSetDlg.Dispose();
			this.Close();
		}

		private void txtDevice_TextChanged(object sender, System.EventArgs e)
		{
			if( DevId != -1 )
			{
				Smc.WExit( DevId );
			}
			string	DeviceName;
			DeviceName = txtDevice.Text;
			Ret = Smc.WInit(DeviceName, out DevId);
			if( Ret!=0 )
			{
				Text_ErrorString = string.Format("SmcWInit = {0:d}", Ret );
				DevId = -1;
			}
			else
			{
				Text_ErrorString = string.Format("SmcWInit = {0:d}", Ret );
			}
			txtErrorString.Text = Text_ErrorString;

            FormUpdate();
		}

		// "AxisNo" Select Change
		private void cboTargetAxis_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			AxisNo=(short)(cboTargetAxis.SelectedIndex + 1);
			FormUpdate();
		}

	}
}
